package com.hildeberto.home.client;

import com.conseilimmo.bo.util.ConstantesConseilImmo;
import java.net.URL;
import java.util.logging.Logger;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MainApp extends Application {

    private static final Logger LOGGER = Logger.getLogger(MainApp.class.getName());
    private static FXMLController controller;
    private static BatimentController batimentController;
    private static LocationController locationController;
    private static LocataireController locataireController;
    private static AgendaController agendaController;
    private static PersonneController personneController;
    private static Stage stage;
    private static Boolean modeAvecBd=true;

    @Override
    public void start(Stage mainStage) throws Exception {
        URL location = getClass().getResource("/fxml/root_scene.fxml");

        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(location);
        fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());

        Parent root2 = (Parent) fxmlLoader.load(location.openStream());

        controller = fxmlLoader.getController();
//
        URL location2 = getClass().getResource("/fxml/batiment_scene.fxml");

        FXMLLoader fxmlLoader2 = new FXMLLoader();
        fxmlLoader2.setLocation(location2);
        fxmlLoader2.setBuilderFactory(new JavaFXBuilderFactory());

        Parent root3 = (Parent) fxmlLoader2.load(location2.openStream());

        batimentController = fxmlLoader2.getController();
//
        URL locationLocation = getClass().getResource(ConstantesConseilImmo.URL_LOCATION);
         FXMLLoader fxmlLoaderLocation = new FXMLLoader();
        fxmlLoaderLocation.setLocation(locationLocation);
        fxmlLoaderLocation.setBuilderFactory(new JavaFXBuilderFactory());

        Parent rootLocation = (Parent) fxmlLoaderLocation.load(locationLocation.openStream());

       locationController = fxmlLoaderLocation.getController();
        //
       //
        URL locationLocataire = getClass().getResource(ConstantesConseilImmo.URL_LOCATAIRE);
         FXMLLoader fxmlLoaderLocataire= new FXMLLoader();
        fxmlLoaderLocataire.setLocation(locationLocataire);
        fxmlLoaderLocataire.setBuilderFactory(new JavaFXBuilderFactory());

        Parent rootLocataire = (Parent) fxmlLoaderLocataire.load(locationLocataire.openStream());

       locataireController = fxmlLoaderLocataire.getController();
        //
        //
        URL locationAgena = getClass().getResource(ConstantesConseilImmo.URL_AGENDA);
         FXMLLoader fxmlLoaderAgenda= new FXMLLoader();
        fxmlLoaderAgenda.setLocation(locationAgena);
        fxmlLoaderAgenda.setBuilderFactory(new JavaFXBuilderFactory());

        Parent rootAgenda= (Parent) fxmlLoaderAgenda.load(locationAgena.openStream());

       agendaController = fxmlLoaderAgenda.getController();
               //
        URL locationPersonne = getClass().getResource(ConstantesConseilImmo.URL_PERSONNE);
         FXMLLoader fxmlLoaderPersonne= new FXMLLoader();
        fxmlLoaderPersonne.setLocation(locationPersonne);
        fxmlLoaderPersonne.setBuilderFactory(new JavaFXBuilderFactory());

        Parent rootPersonne= (Parent) fxmlLoaderPersonne.load(locationPersonne.openStream());

       personneController = fxmlLoaderPersonne.getController();
        if (controller == null) {
            System.out.println("controller 1 null");
        }

        /*FXMLLoader fxmlLoader2 = new FXMLLoader();
         VBox p = (VBox) fxmlLoader2.load(getClass().getResource("/fxml/root_scene.fxml").openStream());
         FXMLController fooController = (FXMLController) fxmlLoader2.getController();
         if(fooController ==null){
         System.out.println("fooController 1 null");
         }*/
        /*FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/root_scene.fxml"));
            
         controller = (FXMLController) fxmlLoader.getController();*/
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/root_scene.fxml"));

        //Parent root = FXMLLoader.load(getClass().getResource("/fxml/liste_batiments_scene.fxml"));
        //Parent root = FXMLLoader.load(getClass().getResource("/fxml/batiment_scene.fxml"));
        Scene scene = new Scene(root);
        scene.getStylesheets().add("/styles/Styles.css");
        stage = new Stage();
        this.stage = mainStage;
        if (controller != null) {
            controller.setApplication(this);
            controller.setRoot(root);
        }

        mainStage.setTitle("Application");
        mainStage.setScene(scene);
        mainStage.show();

    }

    /**
     * The main() method is ignored in correctly deployed JavaFX application.
     */
    public static void main(String[] args) {
        launch(args);
    }

    public static Stage getStage() {
        return stage;
    }

    public static void setStage(Stage stage) {
        MainApp.stage = stage;
    }

    public static FXMLController getController() {
        return controller;
    }

    public static void setController(FXMLController controller) {
        MainApp.controller = controller;
    }

    public static BatimentController getBatimentController() {
        return batimentController;
    }

    public static void setBatimentController(BatimentController batimentController) {
        MainApp.batimentController = batimentController;
    }

    public static LocationController getLocationController() {
        return locationController;
    }

    public static void setLocationController(LocationController locationController) {
        MainApp.locationController = locationController;
    }

    public static LocataireController getLocataireController() {
        return locataireController;
    }

    public static void setLocataireController(LocataireController locataireController) {
        MainApp.locataireController = locataireController;
    }

    public static Boolean getModeAvecBd() {
        return modeAvecBd;
    }

    public static AgendaController getAgendaController() {
        return agendaController;
    }

    public static void setAgendaController(AgendaController agendaController) {
        MainApp.agendaController = agendaController;
    }

    public static PersonneController getPersonneController() {
        return personneController;
    }

    public static void setPersonneController(PersonneController personneController) {
        MainApp.personneController = personneController;
    }


}